﻿using AutoMapper;
using CozeDomain.Entities;
using CozeDto.AdminDtos;
using CozeDto.ConsumptionHistoryDtos;
using CozeDto.ProjectDtos;
using CozeDto.ProjectInstanceDtos;
using CozeDto.RechargeHistoryDtos;
using CozeDto.SaleApplyForDtos;
using CozeDto.SaleHistoryDtos;
using CozeDto.SysDicDtos;
using CozeDto.SysDicTypeDtos;
using CozeDto.TenantsDtos;
using CozeDto.UserDtos;
using CozeDto.WithdrawalDtos;
using D.Util.UtilIoc;

namespace CozeWebApi.Profiles
{
    [AutoMapperProfile]
    public class ExtPerProfile : Profile
    {
        /// <summary>
        /// 构造函数中创建映射关系
        /// </summary>
        public ExtPerProfile()
        {
            CreateMap<SysAdminEntity, RepAdminInfo>().ForMember(dest => dest.TenantIds, opt => opt.Ignore());
            CreateMap<RepAdminInfo, SysAdminEntity>();
            CreateMap<SysAdminEntity, RepAdminPageInfo>();
            CreateMap<ReqUpdateAdmin, SysAdminEntity>();
            CreateMap<ReqAddAdmin, SysAdminEntity>();
            

            CreateMap<ConsumptionHistoryEntity, RepConsumptionHistoryInfo>();
            CreateMap<RepConsumptionHistoryInfo, ConsumptionHistoryEntity>();
            CreateMap<ReqUpdateConsumptionHistory, ConsumptionHistoryEntity>();
            CreateMap<ReqAddConsumptionHistory, ConsumptionHistoryEntity>();

            CreateMap<ProjectEntity, RepProjectInfo>();
            CreateMap<RepProjectInfo, ProjectEntity>();
            CreateMap<ReqUpdateProject, ProjectEntity>();
            CreateMap<ReqAddProject, ProjectEntity>();

            CreateMap<ProjectInstanceEntity, RepProjectInstanceInfo>();
            CreateMap<RepProjectInstanceInfo, ProjectInstanceEntity>();
            CreateMap<ReqUpdateProjectInstance, ProjectInstanceEntity>();
            CreateMap<ReqAddProjectInstance, ProjectInstanceEntity>();

            CreateMap<RechargeHistoryEntity, RepRechargeHistoryInfo>();
            CreateMap<RepRechargeHistoryInfo, RechargeHistoryEntity>();
            CreateMap<ReqUpdateRechargeHistory, RechargeHistoryEntity>();
            CreateMap<ReqAddRechargeHistory, RechargeHistoryEntity>();

            CreateMap<SaleApplyForEntity, RepSaleApplyForInfo>();
            CreateMap<RepSaleApplyForInfo, SaleApplyForEntity>();
            CreateMap<ReqUpdateSaleApplyFor, SaleApplyForEntity>();
            CreateMap<ReqAddSaleApplyFor, SaleApplyForEntity>();

            CreateMap<SaleHistoryEntity, RepSaleHistoryInfo>();
            CreateMap<RepSaleHistoryInfo, SaleHistoryEntity>();
            CreateMap<ReqUpdateSaleHistory, SaleHistoryEntity>();
            CreateMap<ReqAddSaleHistory, SaleHistoryEntity>();

            CreateMap<TenantsEntity, RepTenantsInfo>();
            CreateMap<RepTenantsInfo, TenantsEntity>();
            CreateMap<ReqUpdateTenants, TenantsEntity>();
            CreateMap<ReqAddTenants, TenantsEntity>();

            CreateMap<UserEntity, RepUserInfo>();
            CreateMap<RepUserInfo, UserEntity>();
            CreateMap<ReqUpdateUser, UserEntity>();
            CreateMap<ReqAddUser, UserEntity>();

            CreateMap<SysDicEntity, RepSysDicInfo>();
            CreateMap<RepSysDicInfo, SysDicEntity>();
            CreateMap<ReqUpdateSysDic, SysDicEntity>();
            CreateMap<ReqAddSysDic, SysDicEntity>();

            CreateMap<SysDicTypeEntity, RepSysDicTypeInfo>();
            CreateMap<RepSysDicTypeInfo, SysDicTypeEntity>();
            CreateMap<ReqUpdateSysDicType, SysDicTypeEntity>();
            CreateMap<ReqAddSysDicType, SysDicTypeEntity>();

            CreateMap<WithdrawalEntity, RepWithdrawalInfo>();
            CreateMap<RepWithdrawalInfo, WithdrawalEntity>();
            CreateMap<ReqUpdateWithdrawal, WithdrawalEntity>();
            CreateMap<ReqAddWithdrawal, WithdrawalEntity>();
            //CreateMap<SysAdminEntity, RepAdminInfo>()
            //    .ForMember(dest => dest.Id, opt => opt.MapFrom(s => s.Id))//指定字段一一对应
            //    .ForMember(dest => dest.UUID, opt => opt.MapFrom(s => s.UUID))
            //    .ForMember(dest => dest.Account, opt => opt.MapFrom(s => s.Account))
            //    .ForMember(dest => dest.NickName, opt => opt.MapFrom(s => s.NickName))
            //    .ForMember(dest => dest.Email, opt => opt.MapFrom(s => s.Email))
            //    .ForMember(dest => dest.UserGroupId, opt => opt.MapFrom(s => s.UserGroupId))
            //    .ForMember(dest => dest.RoleId, opt => opt.MapFrom(s => s.RoleId))
            //    .ForMember(dest => dest.IsPush, opt => opt.MapFrom(s => s.IsPush))
            //    .ForMember(dest => dest.Descption, opt => opt.MapFrom(s => s.Descption));

            // 源实体与目标实体的字段名字是一致的，源实体的字段可以与目标实体中的字段数量不一致。
            // 源实体中的字段名字是Getxxx，而目标实体中对应的字段也可以是xxx。
            // 源实体中包含的实体类字段为Sub,里面包含的字段名字为Age，那么目标实体中对应的字段名字可以是：SubAge。

            // 需要配置才能映射到目标实体
            // var config2 = new MapperConfiguration(cfg => cfg.CreateMap<TSource, TDestination>()
            // .ForMember(d => d.DestName, opt => opt.MapFrom(s => s.Name))  //指定字段一一对应
            // .ForMember(d => d.Birthday, opt => opt.MapFrom(s => s.Birthday.ToString("yy-MM-dd HH:mm"))) //指定字段按指定的格式转化
            // .ForMember(d => d.Age, opt => opt.Condition(s => s.Age > 5))  //满足条件才赋值
            // .ForMember(d => d.A1, opt => opt.Ignore())  //忽略该字段，不给该字段赋值
            // .ForMember(d => d.A2, opt => opt.NullSubstitute("Default Value"))  //如果源字段值为空，则赋值为 Default Value
            // .ForMember(d => d.A3, opt => opt.MapFrom(s => s.Name + s.Age * 3 + s.Birthday.ToString("d"))) //自己随意组合赋值

            // Mapping
            // 第一次参数是源类型（这里是Model类型），第二个参数是目标类型（这里是DTO类型）
            // CreateMap<Student, StudentDTO>();

            // 使用自定义映射 Student类的ID映射到StudentDTO类的StudentID
            //CreateMap<Student, StudentDTO>()
            //    .ForMember(destinationMember: des => des.StudentID, memberOptions: opt => { opt.MapFrom(mapExpression: map => map.ID); });

            // 对多个属性进行自定义映射
            //CreateMap<Student, StudentDTO>()
            //    .ForMember(destinationMember: des => des.StudentID, memberOptions: opt => { opt.MapFrom(mapExpression: map => map.ID); })
            //    .ForMember(destinationMember: des => des.StudentName, memberOptions: opt => { opt.MapFrom(mapExpression: map => map.Name); })
            //    .ForMember(destinationMember: des => des.StudentAge, memberOptions: opt => { opt.MapFrom(mapExpression: map => map.Age); })
            //    .ForMember(destinationMember: des => des.StudentGender, memberOptions: opt => { opt.MapFrom(mapExpression: map => map.Gender); });
        }
    }
}
